const ClickOutside = {
  bind(el, binding, vnode) {
    el.__vueClickOutside__ = (event) => {
      // 判断点击是否在元素内部
      if (!el.contains(event.target)) {
        // 执行绑定的回调函数
        vnode.context[binding.expression](event);
      }
    };
    document.addEventListener('click', el.__vueClickOutside__);
  },
  unbind(el) {
    document.removeEventListener('click', el.__vueClickOutside__);
    delete el.__vueClickOutside__;
  }
};

export default ClickOutside;